package com.right.health.app.net;

import com.magics.http.model.HttpParams;
import com.right.health.app.app.App;
import com.right.health.app.bean.FamilyResponse;

import org.json.JSONException;
import org.json.JSONObject;

/*
 * Created by hopeliao on 2019-11-24
 *
 */
public class FamilyApi extends IBaseApi {

    public void getFamilyList(int pageNo) {
        HttpParams params = new HttpParams();

        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());

            PageUtil.addPageJson(jsonObject, pageNo, 50);

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        doPostJson(HttpConstants.API_FAMILY_LIST, params, FamilyResponse.class);
    }

    public void addFamilyMember(String type, String name, String cardNo, String phone) {
        HttpParams params = new HttpParams();

        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("personid", App.getInstance().getUserId());
            jsonObject.put("membername", name);
            jsonObject.put("membership", type);
            jsonObject.put("memberidcard", cardNo);
            jsonObject.put("memberphone", phone);

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        doPostJson(HttpConstants.API_FAMILY_ADD, params, null);
    }

    public void delMember(String memberid) {
        HttpParams params = new HttpParams();

        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("memberid", memberid);

            params.addFormParam("jsonstr", jsonObject.toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        doPostJson(HttpConstants.API_FAMILY_DEL, params, null);
    }
}
